package com.example.demo.mapper;

import java.util.List;

import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import com.example.demo.pojo.User;


@Mapper
public interface UserMapper {
    @Insert("insert into user(username, password, name, phone, email, address, avatar)" +
            " values(#{username}, #{password}, #{name}, #{phone}, #{email}, #{address}, #{avatar})")
    public void insert(User user);

    @Update("update user set username=#{username}, password=#{password}, name=#{name}, phone=#{phone}, email=#{email}, address=#{address}, avatar=#{avatar} " +
            "where id=#{id}")
    public void update(User user);

    @Delete("delete from user where id=#{id}")
    public void delete(Integer id);

    @Select("select * from user order by id desc")
    public List<User> selectAll();

    @Select("select * from user where id=#{id}")
    public User selectById(Integer id);

    @Select("select * from user where name=#{name} order by id desc")
    public List<User> selectByName(String name);

    @Select("select * from user where username=#{username} and name=#{name} order by id desc")
    public List<User> selectByMore(String username, String name);

    @Select("select * from user where username like concat('%',#{username},'%') and name like concat('%',#{name},'%') order by id desc")
    public List<User> selectByLike(String username, String name);

    @Select("select * from user where username like concat('%',#{username},'%') and name like concat('%',#{name},'%') order by id desc limit #{skipNum},#{pageSize}")
    public List<User> selectByPage(Integer skipNum, Integer pageSize, String username, String name);

    @Select("select count(id) from user where username like concat('%',#{username},'%') and name like concat('%',#{name},'%') order by id desc")
    public int selectCount(String username, String name);
    
} 